#include "headfiles.h"

using namespace std;


int main(int argc, char **argv) {
    if (argc != 2) {
        cout << "Usage: " << argv[0] << " file_name" << endl;
        return 0;
    }

    fstream fs;
    fs.open(argv[1]);
    if (!fs.is_open()) {
        cout << "File " << argv[1] << " open error!" << endl;
        return 1;
    }

    string str;
    fs >> str;

    size_t str_size = str.size();
    int *array = (int *)malloc(sizeof(int) * str_size);

    int ret;
    ret = createSuffixArray(str.c_str(), str_size, array);

    size_t i;
    cout << "Input string is:" << endl;
    cout << str << endl << endl;

    cout << "Suffix array is:" << endl;
    for (i = 0; i < str_size; i++) {
        cout << array[i] << ": " << &str[array[i]] << endl;
    }

    return 0;
}

